package com.cy.guava;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.VoidType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.testng.annotations.Test;

/**
 * @author yue.cao
 * @since 11-11-2020
 */
public class DemoWithGuavaCache {


	@Test
	public void t1() {
		int size = 10;
		// int size = 10000000; 会有错误
		Cache<String, Boolean> cache = CacheBuilder.newBuilder()
				.maximumSize(size)
				.recordStats()
				.build();
		for (int i = 0; i < size; i++) {
			cache.put(i + "", true);
		}
		System.out.println(cache.getIfPresent("0"));
		System.out.println(cache.getIfPresent((size - 1) + ""));
		System.out.println(cache.getIfPresent((size) + ""));

		System.out.println(cache.stats());
	}
}
